package service.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import dao.VideoListDao;
import entity.VideoList;
import service.VideoListService;

@Service
public class VideoListServiceImpl implements VideoListService {
	@Autowired
	SqlSessionFactory factory;
	//根据用户的编号查找播单
	@Override
	public List<VideoList> findListByUserId(int userId) {
		SqlSession sqlSession=null;
		try {
			sqlSession=factory.openSession();
			VideoListDao dao = sqlSession.getMapper(VideoListDao.class);
			List<VideoList> list = dao.findListByUserId(userId);
			return list;
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}finally {
			sqlSession.close();
		}
		return null;
	}
	@Override
	public List<VideoList> findByRecentList() {
		SqlSession sqlSession=null;
		try {
			sqlSession=factory.openSession();
			VideoListDao dao = sqlSession.getMapper(VideoListDao.class);
			List<VideoList> list = dao.findByRecentList();
			return list;
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}finally {
			sqlSession.close();
		}
		return null;
	}
	
	@Override
	public int add(VideoList videoList) {
		SqlSession sqlSession=null;
		try {
			sqlSession=factory.openSession();
			VideoListDao dao = sqlSession.getMapper(VideoListDao.class);
			int result = dao.add(videoList);
			sqlSession.commit();
			return result;
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}finally {
			sqlSession.close();
		}
		return 0;
	}

}
